﻿#region USING STATEMENTS
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
#endregion

#region CODE BODY
namespace Fusion.Management
{
    public static class FJoystick
    {
        //////////////////////////////////////////////////
        // Data Fields
        //////////////////////////////////////////////////
        private static GamePadState GPS1Old = GamePad.GetState(PlayerIndex.One);
        private static GamePadState GPS2Old = GamePad.GetState(PlayerIndex.Two);
        private static GamePadState GPS3Old = GamePad.GetState(PlayerIndex.Three);
        private static GamePadState GPS4Old = GamePad.GetState(PlayerIndex.Four);

        private static GamePadState GPS1New = GamePad.GetState(PlayerIndex.One);
        private static GamePadState GPS2New = GamePad.GetState(PlayerIndex.Two);
        private static GamePadState GPS3New = GamePad.GetState(PlayerIndex.Three);
        private static GamePadState GPS4New = GamePad.GetState(PlayerIndex.Four);

        //////////////////////////////////////////////////
        // Public Static Methods
        //////////////////////////////////////////////////
        public static void BeginPoll()
        {
            GPS1New = GamePad.GetState(PlayerIndex.One);
            GPS2New = GamePad.GetState(PlayerIndex.Two);
            GPS3New = GamePad.GetState(PlayerIndex.Three);
            GPS4New = GamePad.GetState(PlayerIndex.Four);
        }
        public static void EndPoll()
        {
            GPS1Old = GPS1New;
            GPS2Old = GPS2New;
            GPS3Old = GPS3New;
            GPS4Old = GPS4New;
        }

        //////////////////////////////////////////////////
        // Public Static Input Methods
        //////////////////////////////////////////////////
        public static bool ButtonDown(PlayerIndex Player, Buttons ToCheck)
        {
            switch (Player)
            {
                case PlayerIndex.One:
                    return GPS1New.IsButtonDown(ToCheck);

                case PlayerIndex.Two:
                    return GPS2New.IsButtonDown(ToCheck);

                case PlayerIndex.Three:
                    return GPS3New.IsButtonDown(ToCheck);

                case PlayerIndex.Four:
                    return GPS4New.IsButtonDown(ToCheck);

                default:
                    return false;
            }
        }
        public static bool ButtonUp(PlayerIndex Player, Buttons ToCheck)
        {
            switch (Player)
            {
                case PlayerIndex.One:
                    return GPS1New.IsButtonUp(ToCheck);

                case PlayerIndex.Two:
                    return GPS2New.IsButtonUp(ToCheck);

                case PlayerIndex.Three:
                    return GPS3New.IsButtonUp(ToCheck);

                case PlayerIndex.Four:
                    return GPS4New.IsButtonUp(ToCheck);

                default:
                    return false;
            }
        }
        public static bool ButtonPressed(PlayerIndex Player, Buttons ToCheck)
        {
            switch (Player)
            {
                case PlayerIndex.One:
                    return (GPS1Old.IsButtonDown(ToCheck) && GPS1New.IsButtonUp(ToCheck));

                case PlayerIndex.Two:
                    return (GPS2Old.IsButtonDown(ToCheck) && GPS2New.IsButtonUp(ToCheck));

                case PlayerIndex.Three:
                    return (GPS3Old.IsButtonDown(ToCheck) && GPS3New.IsButtonUp(ToCheck));

                case PlayerIndex.Four:
                    return (GPS4Old.IsButtonDown(ToCheck) && GPS4New.IsButtonUp(ToCheck));

                default:
                    return false;
            }
        }
        public static Vector2[] PadThumbSticks(PlayerIndex Player)
        {
            switch (Player)
            {
                case PlayerIndex.One:
                    return new Vector2[] { GPS1New.ThumbSticks.Left, GPS1New.ThumbSticks.Right };

                case PlayerIndex.Two:
                    return new Vector2[] { GPS2New.ThumbSticks.Left, GPS2New.ThumbSticks.Right };

                case PlayerIndex.Three:
                    return new Vector2[] { GPS3New.ThumbSticks.Left, GPS3New.ThumbSticks.Right };

                case PlayerIndex.Four:
                    return new Vector2[] { GPS4New.ThumbSticks.Left, GPS4New.ThumbSticks.Right };

                default:
                    return new Vector2[] { Vector2.Zero, Vector2.Zero };
            }
        }
    }
}
#endregion

//////////////////////////////////////////////////////////////////////////////////////////////
// Copyright 2012 Jeffery Thomas Sventora
//////////////////////////////////////////////////////////////////////////////////////////////